package com.csii.ams.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.csii.adhoc.info.user.UserVo;
import com.csii.ams.SearchBean;
import com.csii.ams.service.BusiDefService;
import com.csii.result.APIResult;
import com.csii.result.PageVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * @description:
 * @author: panChuanJiang
 * @create: 2021-08-13 14:20
 */
@RestController
@RequestMapping({"/**/sysuser"})
public class AmsUserController {
    @Autowired
    private BusiDefService busiDefService;
    @RequestMapping(value = "/searchUserByOrgId")
    @ResponseBody
    public APIResult<?> searchUserByOrgId(HttpServletRequest request, @RequestBody Map<String,String> map) {

        String orgId = map.get("orgId");
        String busiCd =  map.get("keyword");
        String tagId =map.get("tagId");
        int pageNo = Integer.parseInt(map.get("pageNo"));
        int pageSize = Integer.parseInt(map.get("pageSize"));
        UserVo userVo = new UserVo();
        userVo.setDepart(orgId);
        SearchBean searchBean = new SearchBean();
        searchBean.setVo(userVo);
        searchBean.setSearchCriteria01(orgId);
        if (!StringUtils.isEmpty(busiCd)){
            searchBean.setSearchCriteria02(busiCd);
        }
        if (!StringUtils.isEmpty(tagId)){
            if ("未归档".equals(tagId)){
                searchBean.setSearchCriteria04(tagId);
            }else {
                searchBean.setSearchCriteria03(tagId);
            }

        }
        String idCard = map.get("idCard");
        if (!StringUtils.isEmpty(idCard)){
            searchBean.setSearchCriteria05(idCard);
        }
        String createdDate = map.get("createdDate");
        if (!StringUtils.isEmpty(createdDate)){
            searchBean.setSearchCriteria06(createdDate);
        }
        String beginDate = map.get("beginDate");
        if (!StringUtils.isEmpty(beginDate)){
            searchBean.setSearchCriteria07(beginDate);
        }
        String endDate = map.get("endDate");
        if (!StringUtils.isEmpty(endDate)) {
            searchBean.setSearchCriteria08(endDate);
        }
        IPage<UserVo> userVoIPage = busiDefService.searchUserByOrgId(searchBean, new Page<>(pageNo, pageSize));
        return APIResult.successResult(PageVo.getPageVoFromIPage(userVoIPage));
    }
}
